package com.study.array;

import java.util.List;

/**
 * @author ytj
 * @date 2021/12/29
 */
public class Method12 {
    public static void main(String[] args) {
        ListNode listNode=new ListNode(1,new ListNode(2,new ListNode(3,new ListNode(4,new ListNode(5)))));
        ListNode resultNode=middleNode(listNode);
        System.out.println(resultNode.val);
    }

    public static ListNode middleNode(ListNode head) {
        ListNode p=head,q=head;
        while (q!=null&&q.next!=null){
            q=q.next.next;
            p=p.next;
        }
        return p;
    }

}
